<template>
    <el-table :data="tableData" style="width: 100%" size="large" :row-style="rowStyle"
        :header-cell-style="{ background: '#F3F3F7' }">
        <el-table-column prop="auditDeptName" label="部门" />
        <el-table-column prop="secondAuditNum" label="送审总数" />
        <el-table-column prop="waitSecondAuditNum" label="待审核数" />
        <el-table-column prop="secondPassNum" label="核价通过" />
        <el-table-column prop="secondRejectNum" label="重新议价" />
        <el-table-column label="通过率">
            <template #default="scope">
                {{ passingRate(scope.row, '通过率') }}
            </template>
        </el-table-column>
        <el-table-column prop="changePriceNum" label="变价数量" />
        <el-table-column prop="revenue" label="营收金额（元）" />
        <el-table-column label="变价率">
            <template #default="scope">
                {{ passingRate(scope.row, '变价率') }}
            </template>
        </el-table-column>
        <el-table-column prop="changeMechanismNum" label="变模式数量" />
    </el-table>
</template>

<script setup lang="ts">
import { defineProps } from 'vue'
const props = defineProps(['tableData'])

// 通过率反显
const passingRate = (row: any, key: string) => {
    if (key === '通过率') {
        let num = Number(row.secondPassNum) / Number(row.secondAuditNum)
        if (!isNaN(num)) {
            return `${(num * 100).toFixed(2)}%`
        } else {
            return '0%'
        }
    } else {
        let num = Number(row.changePriceNum) / Number(row.secondAuditNum)
        if (!isNaN(num)) {
            return `${(num * 100).toFixed(2)}%`
        } else {
            return '0%'
        }
    }
}
const rowStyle = (row: any) => {
    if (row.rowIndex % 2 !== 0) {
        return {
            background: '#F3F3F7'
        }
    } else {
        return {
            background: '#fff'
        }
    }
}
</script>

<style lang="scss" scoped></style>